﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using C1.Win.C1Chart;

namespace LED_Tester
{
    public partial class frmL2 : Form
    {
        public frmL2()
        {
            InitializeComponent();
        }

        #region 变量声明

        private Color[] lineColor = new Color[12] { Color.Red, Color.Green, Color.Blue, Color.Purple, Color.OrangeRed,
            Color.Aqua, Color.Yellow, Color.RoyalBlue, Color.RosyBrown, Color.Violet, Color.Sienna, Color.Firebrick };

        private double gammaSample;
        private double gammaRange;
        private double thetaSample;
        private double thetaDegree;

        private double[] luxData;

        public double GammaSample
        {
            get { return gammaSample; }
            set { gammaSample = value; }
        }
        public double GammaRange
        {
            get { return gammaRange; }
            set { gammaRange = value; }
        }
        public double ThetaSample
        {
            get { return thetaSample; }
            set { thetaSample = value; }
        }
        public double ThetaDegree
        {
            get { return thetaDegree; }
            set { thetaDegree = value; }
        }

        public double[] LuxData
        {
            get { return luxData; }
            set { luxData = value; }
        }

        #endregion

        #region 功能函数

        private void initailize()
        {
            for (int i = 0; i < 12; i++)
            {
                chart2D.ChartGroups[0].ChartData.SeriesList[i].PointData.Clear();
                chart2D.ChartGroups[0].ChartData.SeriesList[i].LineStyle.Color = lineColor[i];
                chart2D.ChartGroups[0].ChartData.SeriesList[i].LineStyle.Thickness = 2;
            }

            chart2D.ChartArea.AxisX.Max = gammaRange;
            chart2D.ChartArea.AxisX.Min = -1 * gammaRange;
        }

        public void Display()
        {
            chart2D.ChartGroups[0].ChartData.SeriesList[(int)(thetaDegree / 15)].PointData.Clear();
            chart2D.ChartGroups[0].ChartData.SeriesList[(int)(thetaDegree / 15)].LineStyle.Color = lineColor[(int)(thetaDegree / 15)];
            chart2D.ChartGroups[0].ChartData.SeriesList[(int)(thetaDegree / 15)].LineStyle.Thickness = 2;

            int length = (int)(2 * gammaRange / gammaSample + 1);

            for (int i = 0; i < length; i++)
            {
                chart2D.ChartGroups[0].ChartData.SeriesList[(int)(thetaDegree / 15)].X.Add(-1 * gammaRange + i * gammaSample);
                chart2D.ChartGroups[0].ChartData.SeriesList[(int)(thetaDegree / 15)].Y.Add(luxData[i]);
            }
        }

        public void Clear()
        {
            for (int i = 0; i < 12; i++)
            {
                chart2D.ChartGroups[0].ChartData.SeriesList[i].PointData.Clear();
                chart2D.ChartGroups[0].ChartData.SeriesList[i].LineStyle.Color = lineColor[i];
                chart2D.ChartGroups[0].ChartData.SeriesList[i].LineStyle.Thickness = 2;
            }
        }

        public C1Chart Return()
        {
            return chart2D;
        }

        #endregion

        #region 窗体事件

        private void frmL2_Load(object sender, EventArgs e)
        {
            initailize();
        }

        private void frmL2_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        #endregion
    }
}
